

gl path "~/Dropbox/CovidTurnout/replication"


set scheme plotplain

* Bring in voter data
use "$path/original_data/tx_propensity.dta", clear

* Generate indicators
gen voted2020 = method20 != .
gen absentee2020 = method20 == 1

gen voted2016 = method16 != .
gen absentee2016 = method16 == 1

* Generate indicators for midterms
gen voted2018 = method18 != . 
gen absentee2018 = method18 == 1

gen voted2014 = method14 != . 
gen absentee2014 = method14 == 1

* Generate running variable
gen running_2020 = mdy(11, 03, 2020) - mdy(month(dob20), day(dob20), year(dob20) + 65)
gen running_2016 = mdy(11, 06, 2016) - mdy(month(dob16), day(dob16), year(dob16) + 65)
gen running_2018 = mdy(11, 06, 2018) - mdy(month(dob20), day(dob20), year(dob16) + 65)
gen running_2014 = mdy(11, 04, 2014) - mdy(month(dob16), day(dob16), year(dob16) + 65)

local bw = 700

* TURNOUT ANALYSIS -----------------------------------
forvalues j = 2014 (2) 2020 {

		preserve
		if `j' == 2016 keep if method12 != .
		if `j' == 2020 keep if method16 != .
		if `j' == 2014 keep if method12 != .
		if `j' == 2018 keep if method16 != .
		
		keep if inrange(running_`j', -`bw', `bw')

		rdrobust voted`j' running_`j', p(2)

		rdplot voted`j' running_`j', genvars nbins(50) ///
			graph_options(legend(off) xtitle("Days since 65th birthday") ///
			ytitle("% Absentee Votes")) shade genvars p(4) ci(95)
		
		collapse (mean) rdplot_* , by(running_`j')
		gen year = `j'
	

		if `j' == 2014 tempfile combinedturnout
		else append using `combinedturnout'
		save `combinedturnout', replace
		restore
}  

preserve
use `combinedturnout', clear
graph display, ysize(5) xsize(3)
twoway (scatter rdplot_mean_y rdplot_mean_bin if year == 2020, sort msize(small)  mcolor(gs40)) ///
	(scatter rdplot_mean_y rdplot_mean_bin if year == 2016, sort msize(small)  mcolor(gray)) ///
	(line rdplot_hat_y running_2016 if running_2016<0 & year == 2016, lc(gray) sort lw(thick) lp(solid)) ///
	(line rdplot_hat_y running_2016 if running_2016>=0 & year == 2016, lc(gray) sort lw(thick) lp(solid)) ///
	(line rdplot_hat_y running_2020 if running_2020<0 & year == 2020, lc(black) sort lw(thick) lp(solid)) ///
	(line rdplot_hat_y running_2020 if running_2020>=0 & year == 2020, lc(black) sort lw(thick) lp(solid)), ///
	xline(0, lc(black) lw(medthin) lp(dashed)) ///
	yscale(r(0.75, 0.9)) ylabel(0.75(0.05)0.9) ///
	text(0.835 -200 "2020", size(large)) text(0.775 -200 "2016", size(large)) ///
	legend(off) xti("Days since 65th Birthday", size(large)) yti("Turnout", size(large)) ///
	scale(1.2)

graph export "$path/output/tx_rd_turnout_general.pdf", replace
restore

preserve
use `combinedturnout', clear
graph display, ysize(5) xsize(3)
twoway (scatter rdplot_mean_y rdplot_mean_bin if year == 2014, sort msize(small)  mcolor(gray)) ///
	(scatter rdplot_mean_y rdplot_mean_bin if year == 2018, sort msize(small)  mcolor(gs40)) ///
	(line rdplot_hat_y running_2014 if running_2014 <0 & year == 2014, lc(gray) sort lw(thick) lp(solid)) ///
	(line rdplot_hat_y running_2014 if running_2014>=0 & year == 2014, lc(gray) sort lw(thick) lp(solid)) ///
	(line rdplot_hat_y running_2018 if running_2018 <0 & year == 2018, lc(black) sort lw(thick) lp(solid)) ///
	(line rdplot_hat_y running_2018 if running_2018>=0 & year == 2018, lc(black) sort lw(thick) lp(solid)), ///
	xline(0, lc(black) lw(medthin) lp(dashed)) ///
	text(0.78 -300 "2018", size(large)) text(0.625 300 "2014", size(large)) ///
	yscale(r(0.6, 0.85)) ylabel(0.6(0.05)0.85) ///
	legend(off) xti("Days since 65th Birthday", size(large)) yti("Turnout", size(large)) ///
	scale(1.2)

graph export "$path/output/tx_rd_turnout_midterm.pdf", replace
restore

* ABSENTEE SHARE ANALYSIS ---------------------------
forvalues j = 2014 (2) 2020 {
		preserve
		if `j' == 2016 keep if method16 != .
		if `j' == 2020 keep if method20 != .
		if `j' == 2014 keep if method14 != .
		if `j' == 2018 keep if method18 != .
		
		keep if inrange(running_`j', -`bw', `bw')

		rdplot absentee`j' running_`j', genvars nbins(50) ///
			graph_options(legend(off) xtitle("Days since 65th birthday") ///
			ytitle("% Absentee Votes")) shade genvars p(4) ci(95)
		
		collapse (mean) rdplot_* , by(running_`j')
		gen year = `j'
	

		if `j' == 2014 tempfile combinedturnout
		else append using `combinedturnout'
		save `combinedturnout', replace
		restore
}  

preserve
use `combinedturnout', clear
graph display, ysize(5) xsize(3)
twoway (scatter rdplot_mean_y rdplot_mean_bin if year == 2020, sort msize(small) mcolor(gs)) ///
	(scatter rdplot_mean_y rdplot_mean_bin if year == 2016, sort msize(small) mcolor(gray)) ///
	(line rdplot_hat_y running_2016 if running_2016<0 & year == 2016, lc(gray) sort lw(thick) lp(solid)) ///
	(line rdplot_hat_y running_2016 if running_2016>=0 & year == 2016, lc(gray) sort lw(thick) lp(solid)) ///
	(line rdplot_hat_y running_2020 if running_2020<0 & year == 2020, lc(black) sort lw(thick) lp(solid)) ///
	(line rdplot_hat_y running_2020 if running_2020>=0 & year == 2020, lc(black) sort lw(thick) lp(solid)), ///
	xline(0, lcolor(black) lwidth(medthin) lpattern(dashed)) ///
	yscale(r(0.0, 0.2)) ylabel(0.0(0.05)0.2) ///
	text(0.15 300 "2020", size(large)) text(0.05 300 "2016", size(large)) ///
	legend(off) xti("Days since 65th Birthday", size(large)) yti("Share Absentee", size(large)) ///
	scale(1.2)
graph export "$path/output/tx_rd_absentee_general.pdf", replace
restore

preserve
use `combinedturnout', clear
graph display, ysize(5) xsize(3)
twoway (scatter rdplot_mean_y rdplot_mean_bin if year == 2014, sort msize(small) mcolor(gray)) ///
	(scatter rdplot_mean_y rdplot_mean_bin if year == 2018, sort msize(small) mcolor(gs40)) ///
	(line rdplot_hat_y running_2014 if running_2014 <0 & year == 2014, lc(gray) sort lw(thick) lp(solid)) ///
	(line rdplot_hat_y running_2014 if running_2014>=0 & year == 2014, lc(gray) sort lw(thick) lp(solid)) ///
	(line rdplot_hat_y running_2018 if running_2018 <0 & year == 2018, lc(black) sort lw(thick) lp(solid)) ///
	(line rdplot_hat_y running_2018 if running_2018>=0 & year == 2018, lc(black) sort lw(thick) lp(solid)), ///
	xline(0, lcolor(black) lwidth(medthin) lpattern(dashed)) ///
	yscale(r(0.0, 0.15)) ylabel(0.0(0.05)0.15) ///
	text(0.07 300 "2018", size(large)) text(0.13 250 "2014", size(large)) ///
	legend(off) xti("Days since 65th Birthday", size(large)) yti("Share Absentee", size(large)) ///
	scale(1.2)
graph export "$path/output/tx_rd_absentee_general_midterm.pdf", replace
restore
